// 🎨 颜色分配流程测试脚本
// 在浏览器控制台中运行此脚本来测试颜色分配

console.log('🎨 开始测试颜色分配流程...')

// 检查全局对象
console.log('检查全局对象:')
console.log('- window.colorDebugger:', !!window.colorDebugger)
console.log('- window.gameStore:', !!window.gameStore)
console.log('- window.signalRService:', !!window.signalRService)

// 检查 GameStore 状态
if (window.gameStore) {
  console.log('\n📊 GameStore 当前状态:')
  console.log('- currentPlayer:', window.gameStore.currentPlayer)
  console.log('- players:', window.gameStore.players)
  console.log('- currentRoom:', window.gameStore.currentRoom)
  console.log('- isConnected:', window.gameStore.isConnected)
} else {
  console.log('❌ GameStore 未找到')
}

// 检查 SignalR 服务状态
if (window.signalRService) {
  console.log('\n🔗 SignalR 服务状态:')
  console.log('- isConnected:', window.signalRService.isConnected)
  console.log('- connectionId:', window.signalRService.getConnectionId())
  console.log('- messageQueue:', window.signalRService.getMessageQueueStatus())
} else {
  console.log('❌ SignalR 服务未找到')
}

// 测试颜色分配函数
function testColorAssignment() {
  console.log('\n🧪 测试颜色分配...')
  
  if (!window.gameStore) {
    console.log('❌ GameStore 不可用')
    return
  }
  
  // 模拟玩家数据
  const testPlayer = {
    id: 'test-player-' + Date.now(),
    nickname: '测试玩家',
    avatarColor: '#ff6b6b',
    brushColor: '#c44569',
    isOwner: false
  }
  
  console.log('测试玩家数据:', testPlayer)
  
  // 测试 addPlayer
  console.log('\n1. 测试 addPlayer...')
  window.gameStore.addPlayer(testPlayer)
  console.log('添加后的玩家列表:', window.gameStore.players)
  
  // 测试 setCurrentPlayer
  console.log('\n2. 测试 setCurrentPlayer...')
  window.gameStore.setCurrentPlayer(testPlayer)
  console.log('设置后的当前玩家:', window.gameStore.currentPlayer)
  
  // 检查颜色一致性
  if (window.colorDebugger) {
    console.log('\n3. 检查颜色一致性...')
    const issues = window.colorDebugger.checkColorConsistency(window.gameStore.players)
    if (issues.length === 0) {
      console.log('✅ 颜色一致性检查通过')
    } else {
      console.log('⚠️ 发现颜色问题:', issues)
    }
  }
}

// 测试 SignalR 事件
function testSignalREvents() {
  console.log('\n🔔 测试 SignalR 事件...')
  
  if (!window.signalRService) {
    console.log('❌ SignalR 服务不可用')
    return
  }
  
  // 测试事件监听器
  const testCallback = (data) => {
    console.log('✅ 测试事件回调被触发:', data)
  }
  
  window.signalRService.on('TestEvent', testCallback)
  console.log('已添加测试事件监听器')
  
  // 触发测试事件
  window.signalRService.triggerEvent('TestEvent', { message: '测试事件' })
  
  // 清理
  window.signalRService.off('TestEvent', testCallback)
  console.log('已清理测试事件监听器')
}

// 运行测试
console.log('\n🚀 运行测试...')
testColorAssignment()
testSignalREvents()

console.log('\n✨ 测试完成！')
console.log('💡 提示: 如果看到错误，请确保页面已完全加载并且已连接到 SignalR 服务器')
